<?php
/*
 * @author Jens Beyer
 * @date 04-15-2012
 */
class Ajax_Model_Tabs_InsertTab_Normal extends Ajax_Model
{
    protected $_normalData;

    public function insert()
    {
    }

    public function getAllNormalData()
    {
        $normalData = array();
        $normalData["pitu"] = "any data One";
        $normalData["lala"] = "any data Two";
        $this->_normalData = $normalData;
        return $this->_normalData;
    }

    public function fetch()
    {
//        $this->insert();
        return $this;
    }

    /**
     *
     * @return string
     */
    public function returnAjax()
    {
        $normalData = $this->getAllNormalData();
        $this->getAt()->assign('normalData', $normalData);
        $content = $this->getAt()->fetch('Tabs/InsertTab/Normal/data.tpl');
        $navigationToDiv = str_replace("Ajax_Model_Tabs_", "", get_class($this));
        $navigationToDiv = '#' . str_replace("_", " > #", $navigationToDiv);
        $fetchedData = array();
        $templateData = array();
        $templateData['navigationToDiv'] = $navigationToDiv;
        $templateData['divToReplace'] = '#data';
        $templateData['content'] = $content;
        $fetchedData[] = $templateData;
        ob_start();
        print_r('$fetchedData = ');
        print_r($fetchedData);
        print_r("\n");
        $text = ob_get_clean();
        error_log($text);
        $fetchedDivDataJson = json_encode($fetchedData);
        return $fetchedDivDataJson;
    }

    /**
     * @return Smarty
     */
    public function getAt()
    {
        if (!$this->_at) {
            $this->_at = Controller::getActionTemplate();
        }
        return $this->_at;
    }

    /**
     *
     * @param Smarty $at
     */
    public function setAt(Smarty $at)
    {
        $this->_at = $at;
    }

    /**
     *
     * @return MyDb
     */
    public function getDb()
    {
        if (!$this->_db) {
            $this->_db = Controller::getDatabase("localhost");
        }
        return $this->_db;
    }

    /**
     *
     * @param Db $db
     */
    public function setDb(Db $db)
    {
        $this->_db = $db;
    }
}